package gmusic.command;

import gmusic.bo.ArtistBean;
import gmusic.bo.ReleaseBean;
import gmusic.bo.TrackBean;
import gmusic.services.impl.GMusicServicesImpl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class AfficherReleaseTracks implements Command {

	/*
	 * private final static Logger log = Logger
	 * .getLogger(AfficherReleaseTracks.class);
	 */

	public String execute(HttpServletRequest req) throws Exception {

		HttpSession session = req.getSession();
		String rgmidS = req.getParameter("rgmid");
		String tgmidS = req.getParameter("tgmid");
		ReleaseBean release = null;
		TrackBean track = null;

		if (rgmidS != null) {
			release = GMusicServicesImpl.getInstance()
					.getReleaseSearchWithGmid(Integer.parseInt(rgmidS));
		} else {
			track = GMusicServicesImpl.getInstance().getTrackSearchWithGmid(
					Integer.parseInt(tgmidS));
			release = GMusicServicesImpl.getInstance()
					.getReleaseSearchWithGmid(track.getReleaseId());
		}
		List<TrackBean> tracks = GMusicServicesImpl.getInstance()
				.getTracksSearchWithGmid(release.getGmid());
		ArtistBean artist = GMusicServicesImpl.getInstance()
				.getArtistSearchWithGmid(release.getArtistGmid());

		session.setAttribute("groupe", artist);
		session.setAttribute("album", release);
		session.setAttribute("chansons", tracks);

		return "/afficherChansonsAlbum.jsp";
	}
}
